﻿using UnityEngine;
using System.Collections;
using Dict.DataModel;
using System.Text;
namespace Room
{
    public class RCLODPet : RCLODBase
    {
        public RCLODPet(RoomCharactor owner)
            : base(owner)
        {
            type = LODType.Pet;
        }

        protected string modelName = "";

        protected bool running = false;     //运行中
        protected bool inView = false;    //视野内

        protected string petId;

        protected TablePet dictPet;

        public void Init(string petId)
        {
            this.petId = petId;

            dictPet = Dict.Blo.DictPetBlo.GetTablePet(petId);


            this.modelName = dictPet.resName;

            if (model == null)
            {
                LoadModel(modelName);
            }
        }




        public override void DoStart()
        {
            ShowShadow();
            PlayAnim("stand", WrapMode.Loop);
        }

        public override void DoStop()
        {
            UnloadModel();
        }

        public override void DoResume()
        {
            base.DoResume();
            running = true;

            if (model == null)
            {
                LoadModel(modelName);
            }
        }

        public override void DoPause()
        {
            base.DoPause();
            running = false;

            if (model == null)
            {
                LoadModel(modelName);
            }
        }
        public static bool usingLod = true;

        public override void SetLevel(int lodLevel)
        {
            if (GetLevel() != lodLevel)
            {
                base.SetLevel(lodLevel);
                UnloadModel();
                if(model==null)
                {
                    LoadModel(modelName);
                }
            }

        }
        public override void SetInView(bool inView)
        {
            base.SetInView(inView);
            this.inView = inView;
            if (model == null)
            {
                LoadModel(modelName);
            }
        }
        public override bool GetInView()
        {
            return inView;
        }

       
        protected override void OnLoadModelComplete()
        {
            base.OnLoadModelComplete();
            CommonMethod.ChangeLayer(model.transform, LayerName.SceneActor);
            model.SetActive(true);
            model.GetComponent<ModelRenderKit>().SetModelScale((float)dictPet.Scale);
        }
    }
}

